package io.osw.modules.sys.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;

import io.osw.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.osw.modules.sys.entity.TblVendorEntity;
import io.osw.modules.sys.service.TblVendorService;
import io.osw.common.utils.PageUtils;
import io.osw.common.utils.R;



/**
 * 供应商表
 *
 * @author guxiaoguang
 * @email xuebai864627555@gmail.com
 * @date 2019-01-06 21:41:25
 */
@RestController
@RequestMapping("sys/tblvendor")
public class TblVendorController extends AbstractController{
    @Autowired
    private TblVendorService tblVendorService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("sys:tblvendor:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = tblVendorService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{vendorId}")
    @RequiresPermissions("sys:tblvendor:info")
    public R info(@PathVariable("vendorId") Long vendorId){
        TblVendorEntity tblVendor = tblVendorService.selectById(vendorId);

        return R.ok().put("tblVendor", tblVendor);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("sys:tblvendor:save")
    public R save(@RequestBody TblVendorEntity tblVendor){
        tblVendor.setCreateTime(new Date());
        tblVendor.setCreateBy(getUserId());
        tblVendor.setCompanyId(getUser().getCompanyId());
        tblVendorService.insert(tblVendor);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sys:tblvendor:update")
    public R update(@RequestBody TblVendorEntity tblVendor){
        ValidatorUtils.validateEntity(tblVendor);
        tblVendor.setUpdateTime(new Date());
        tblVendor.setUpdateBy(getUserId());
        tblVendorService.updateAllColumnById(tblVendor);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("sys:tblvendor:delete")
    public R delete(@RequestBody Long[] vendorIds){
        tblVendorService.deleteBatchIds(Arrays.asList(vendorIds));

        return R.ok();
    }

}
